package com.ebupt.migu.music.strategy.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
@DS("mysql_mg")
public interface StrategyMapper {

    /**
     * 创建策略
     *
     * @param params
     */
    void addStrategy(Map<String, Object> params);

    /**
     * 统计当前条件下的策略总数
     *
     * @param params
     * @return
     */
    Integer countStrategyList(Map<String, Object> params);

    /**
     * 分页、条件查询策略列表
     *
     * @param params
     * @return
     */
    List<HashMap<String, Object>> strategyList(Map<String, Object> params);

    /**
     * 查询是否存在同名策略
     *
     * @return
     */
//    boolean isExist(String strategyName, String strategyId);
    boolean isExist(Map<String, Object> map);

    /**
     * 更新策略信息
     *
     * @param params
     */
    void updateStrategy(Map<String, Object> params);

    /**
     * 中止/终止策略执行
     *
     * @param params
     */
    void endExecute(Map<String, Object> params);

    void updateStatus(@Param("strategyId") String strategyId, @Param("status") byte status);

    /**
     * 删除策略
     */
    void deleteStrategyById(Map<String, Object> map);

    /**
     * 审批后修改策略执行状态
     *
     * @param params
     */
    void updateApproveInfo(Map<String, Object> params);

    /**
     * 通过策略ID查询策略详情
     *
     * @param strategyId
     * @return
     */
    Map<String, Object> queryByStrategyId(String strategyId);

    String[] queryWhites();

    /**
     * 通过策略名称查询策略详情
     *
     * @return
     */
    Map<String, Object> queryStrategyDetailByName(Map<String, Object> params);

    /**
     * 中止/终止策略执行
     *
     * @param params
     */
    void pause(Map<String, Object> params);

    /**
     * 批量创建策略
     *
     * @param paramsList
     */
    void addStrategyList(@Param("paramsList") List<Map<String, Object>> paramsList);

    /**
     * Revocation strategy by id.
     *
     * @param params the params
     */
    void revocationStrategyById(Map<String, Object> params);

    Integer queryGroupStatusByStrategyId(@Param("strategyId") String strategyId);

    /**
     * 查询使用该人群的待进行策略
     *
     * @param groupId 人群id
     * @return 策略集合
     */
    List<Map<String, Object>> queryStrategyByGroupId(@Param("groupId") String groupId);


    @Select("SELECT mobile FROM sys_user WHERE login_name = #{approvalId}")
    String getMobile(@Param("approvalId") String approvalId);


    @Insert("INSERT INTO market_sms_number (number_id, strategy_id, approval_id) VALUES (#{randomNumber}, #{strategyId}, #{approvalId})")
    int insertNumber(@Param("randomNumber") String randomNumber, @Param("strategyId") String strategyId, @Param("approvalId") String approvalId);

    @Delete("DELETE FROM market_sms_number WHERE strategy_id = #{strategyId}")
    int deleteNumber(@Param("strategyId") String strategyId);

    @Select("SELECT * FROM market_sms_number WHERE number_id = #{randomNumber}")
    Map selectNumber(@Param("randomNumber") String randomNumber);

}
